package org.reenscape.skill;
import org.reenscape.model.*;
import org.reenscape.lib.*;
import java.io.*;
public class Healing {

		public String line;
		public String[] foodtoken = new String[10];
		public boolean loadfound = false;
		public boolean filedone = false;
		public boolean[] foodExist = new boolean[9999];
		public int[] foodHP = new int[9999];
		public int[] foodLvl = new int[9999];
		public int[] foodLAdd = new int[9999];
		public int[] foodAfter = new int[9999];
		public BufferedReader foodlist;
		
		public void load() {
			try {
				foodlist = new BufferedReader(new FileReader("config/food.cfg"));
				loadfound = true;
			} catch(FileNotFoundException fileex) {
				System.out.println("[E] Could not find food.cfg!");
			}
			if(loadfound) {
				int foodID;
				try {
					while (!filedone) {
						String line = foodlist.readLine();
						if(line == null) {
							filedone = true;
						} else {
							if (line.startsWith("//") == false && line.startsWith(" //") == false) {
								foodtoken = line.split("\t");
								foodID = Integer.parseInt(foodtoken[0]);
								foodExist[foodID] = true;
								foodHP[foodID] = Integer.parseInt(foodtoken[1]);
								foodLvl[foodID] = Integer.parseInt(foodtoken[3]);
								foodLAdd[foodID] = Integer.parseInt(foodtoken[4]);
								foodAfter[foodID] = Integer.parseInt(foodtoken[2]);
							}
						}
					}
					System.out.println("Loaded food!");
				} catch(IOException ioexception) {
					System.out.println("[E] error parsing food file");
				}
			}
		}
		
		public boolean eat(int eatFoodID, int eatFoodSlot, PacketParser p3) {
			int i = 1;
			if(foodExist[eatFoodID]) {
				p3.sendMessage("You eat the "+p3.GetItemName(eatFoodID)+".");
				p3.Animation(0x33D);
				p3.deleteItem(eatFoodID, eatFoodSlot, 1);
				int Heal = foodHP[eatFoodID];
				int HealDiff = (foodHP[eatFoodID] - foodHP[eatFoodID]);
				if(HealDiff > 0) { Heal += Library.mutil.random(HealDiff); }
				if(foodAfter[eatFoodID] != -1) {
				p3.addItem(foodAfter[eatFoodID], 1);
				}
				p3.NewHP =(p3.playerLevel[p3.playerHitpoints] + Heal);
				if(p3.NewHP >= p3.getLevelForXP(p3.playerXP[p3.playerHitpoints])) {
					p3.NewHP = p3.getLevelForXP(p3.playerXP[p3.playerHitpoints]); 
				}
				if(foodLAdd[eatFoodID] != 0) { p3.playerLevel[foodLvl[eatFoodID]] = (p3.getLevelForXP(p3.playerXP[foodLvl[eatFoodID]]) + foodLAdd[eatFoodID]); }
					p3.resetAnimation();
					return true;
				} else {
					return false;
				}
		}
}